// 导入组件
import Login from '@/views/Login'
import Home from '@/views/Home'
import Register from '@/views/Register'
import Search from '@/views/Search'
import Detail from '@/views/Detail'
import AddCartSuccess from '@/views/AddCartSuccess'
import ShopCart from '@/views/ShopCart'
import Trade from '@/views/Trade'
import Pay from '@/views/Pay'
import PaySuccess from '@/views/PaySuccess'
import Center from '@/views/Center'
// 二级路由
import myOrder from '@/views/Center/myOrder'
import groupOrder from '@/views/Center/groupOrder'

export default [
  {
    path:'/center',
    component:Center,
    children:[
      {
        path:'myorder',
        name:'myorder',
        component:myOrder
      },
      {
        path:'grouporder',
        name:'grouporder',
        component:groupOrder
      },
      {
        path:'',
        redirect:'/center/myorder'
      }
    ],
    meta:{is_show_footer:true}
   },
  {
    path:'/paysuccess',
    name:'paysuccess',
    component:PaySuccess,
    beforeEnter: (to, from, next) => {
      // ...
      //只有从pay组件进入才能进入paysuccess组件
      if(from.name ==='pay'){
        next()
      }else{
        // 如果不是从pay组件进入，则中断跳转
        next(false)
      }
    },
    meta:{is_show_footer:true}
   },
  {
    path:'/pay',
    name:'pay',
    component:Pay,
    beforeEnter: (to, from, next) => {
      // ...
      //只有从trade组件进入才能进入trade组件
      if(from.name ==='trade'){
        next()
      }else{
        // 如果不是从trade组件进入，则中断跳转
        next(false)
      }
    },
    meta:{is_show_footer:true}
   },
  {
    path:'/trade',
    name:'trade',
    component:Trade,
    // 路由独享守卫
    beforeEnter: (to, from, next) => {
      // ...
      //只有从shopcart组件进入才能进入trade组件
      if(from.name ==='shopcart'){
        next()
      }else{
        // 如果不是从shopcart组件进入，则中断跳转
        next(false)
      }
    },
    meta:{is_show_footer:true}
   },
  {
    path:'/shopcart',
    name:'shopcart',
    component:ShopCart,
    meta:{is_show_footer:true}
   },
  {
    path:'/addcartsuccess',
    name:'addcartsuccess',
    component:AddCartSuccess,
    meta:{is_show_footer:true}
   },
  {
    path:'/detail/:skuId',
    name:'detail',
    component:Detail,
    meta:{is_show_footer:true}
   },
   {
    path:'/home',
    name:'home',
    component:Home,
    meta:{is_show_footer:true}
   },
   {
    path:'/login',
    name:'login',
    component:Login,
    meta:{is_show_footer:false}
   },
   {
    path:'/register',
    name:'register',
    component:Register,
    meta:{is_show_footer:false}
   },
   {
    // :keyword 是一个占位符，用来匹配关键字 ?keyword 表示可选参数
    path:'/search/:keyword?',
    name:'search',
    component:Search,
    meta:{is_show_footer:true}
   },
  //重定向跳转主页面
  {
    path:'*',
    redirect:'/home'
  }
]